package com.yegs.jltqc.controller;

import com.yegs.jltqc.config.Msg;
import com.yegs.jltqc.util.FileUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/file")
public class FileController {

    @PostMapping("/upload")
    public Msg upload(@RequestParam("file") MultipartFile file){
        try {
            if (!file.isEmpty()){
                String filename = FileUtils.upload(file);
                return Msg.success("data",filename);
            }else {
                return Msg.error("文件不能是空");
            }
        } catch (IOException e) {
            e.printStackTrace();
            return Msg.error(e.getMessage());
        }
    }

}
